#!/usr/bin/python                             
#-*- coding:utf-8 -*-  

import RPi.GPIO as GPIO
import time
import rospy
from robot_pkg.msg import Person1


class Light(object):
	def __init__(self):
		self.Relays3_GPIO = 19 #继电器3GPIO 高电平使能
		#设置GPIO
		GPIO.setwarnings(False)
		GPIO.setmode(GPIO.BCM)
		GPIO.setup(self.Relays3_GPIO, GPIO.OUT)
		GPIO.output(self.Relays3_GPIO, 1)
		
	#控制继电器
	def ConrtolRelays(self,data):
		if data == 1:#打开
			GPIO.output(self.Relays3_GPIO, 1)
			time.sleep(1)
		if data == 2:#关闭
			GPIO.output(self.Relays3_GPIO, 0)
			time.sleep(1)
			
	
	def get_data(self,msg):	
		self.ConrtolRelays(msg.Relays3)
		
	def main(self):
		rospy.init_node('Light', anonymous=True)
		#链接服务器
		rospy.Subscriber("/client_publisher", Person1, self.get_data,queue_size=100)

		rospy.spin()
	



if __name__ == '__main__':
	try :    
		p = Light()
		p.main()
	except rospy.ROSInterruptException:
		pass
    
    
    
    
    
    

        
        
